﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;

namespace MyTime.WPF.Core
{
    public static class Extensions
    {
        public static void FadeIn(this Window win, double animationSeconds)
        {
            if (win.Visibility == Visibility.Visible && win.Opacity != 0)
                return;
            win.Opacity = 0;
            win.Visibility = System.Windows.Visibility.Visible;
            var anim = new DoubleAnimation(0, 1, (Duration)TimeSpan.FromSeconds(animationSeconds));
            win.BeginAnimation(UIElement.OpacityProperty, anim);
        }
        public static void FadeOut(this Window win, double animationSeconds)
        {
            var anim = new DoubleAnimation(0, (Duration)TimeSpan.FromSeconds(animationSeconds));
            anim.Completed += (s, _) => win.Hide();
            win.BeginAnimation(UIElement.OpacityProperty, anim);
        }
    }
}
